<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    template="/layout/template.xhtml">

	<ui:define name="currency">
		<ui:include src="/layout/currency.xhtml" >
			<ui:param name="viewManager" value="#{kBasketManager}" />
			<ui:param name="reRenderIds" value="basket_id" />
		</ui:include>
    </ui:define>

    <ui:define name="l_content">
		<ui:include src="/l_content/lc.xhtml" />
    </ui:define>
    
    <ui:define name="body">
    	<h:panelGroup id="basket_id">
    		<h:form id="basket_form">
	   			<h:outputText value="#{messages.basket_msg}" />
	   			<br />
	   			<a:commandButton action="#{kBasketManager.save()}" rendered="#{kBasketManager.list.size gt 0}"
	   				reRender="basket_id, messages" value="#{messages.save_msg}" />
	   			<br />
    			<h:outputText value="#{messages.items_msg}: #{kBasketManager.list.size}" />
	    		<rich:dataTable id="it_id" value="#{kBasketManager.list}" var="e" rowKeyVar="i" >
	    			<rich:column styleClass="tac" width="10%">
	   					<f:facet name="header">
	   						<h:outputText value="#{messages.img_msg}" />
	   					</f:facet>
	   					<a href="#{facesContext.externalContext.requestContextPath}/k_item.k?itemId=#{e.item.id}" >
	  						<img src="/#{kInitParam.imgPath}/i_#{e.img.itemId}/#{e.img.thumb}" width="50" height="50"/>	   					
	   					</a>
	   				</rich:column>
	    			<rich:column styleClass="tac" width="5%">
	    				<f:facet name="header">
	    					<h:outputText value="#{messages.id_msg}" />
	    				</f:facet>
	    				<h:outputText value="#{e.item.id}" />
	    			</rich:column>
	    			<rich:column>
	    				<f:facet name="header">
	    					<h:outputText value="#{messages.name_msg}" />
	    				</f:facet>
	    				<h:outputText value="#{e.item.getName(kUser.klang)}" />
	    			</rich:column>
	    			<rich:column>
	    				<f:facet name="header">
	    					<h:outputText value="#{messages.color_msg}" />
	    				</f:facet>
	    				<h:outputText value="#{e.itemColor.color.color.getName(kUser.klang)}" />
	    			</rich:column>
	    			<rich:column>
	    				<f:facet name="header">
	    					<h:outputText value="#{messages.size_msg}" />
	    				</f:facet>
	    				<h:outputText value="#{e.itemSize.size.size.code}" />
	    			</rich:column>
	    			<rich:column>
	    				<f:facet name="header">
	    					<h:outputText value="#{messages.material_msg}" />
	    				</f:facet>
	    				<h:outputText value="#{e.itemMaterial.material.material.getName(kUser.klang)}" />
	    			</rich:column>
	    			<rich:column>
	    				<f:facet name="header">
	    					<h:outputText value="#{messages.kadrons_msg}" />
	    				</f:facet>
	    				<h:outputText value="#{e.item.kadrons} K" />
	    			</rich:column>
	    			<rich:column styleClass="tar">
	    				<f:facet name="header">
	    					<h:outputText value="#{messages.price_msg}" />
	    				</f:facet>
	    				<s:fragment rendered="#{e.delPrice}">
							<del>
	   							<h:outputText value="#{e.price.price} #{kUser.currency.sign}" 
	   								title="#{messages.price_msg}"
	   								styleClass="bsk_del_item_price" />
 							</del>&#160;
 						</s:fragment>
 						<s:fragment rendered="#{!e.delPrice}">
  							<h:outputText value="#{e.price.price} #{kUser.currency.sign}" 
  								title="#{messages.price_msg}"
  								styleClass="bsk_item_price" />
 						</s:fragment>
						<s:fragment rendered="#{e.discounted}">
 							<s:fragment rendered="#{e.delDiscountPrice}">
  								<del>
	    							<h:outputText value="#{e.price.discountPrice} #{kUser.currency.sign}" 
	    								title="#{messages.discount_price_msg}"
	    								styleClass="bsk_del_item_price" />
  								</del>
  							</s:fragment>
  							<s:fragment rendered="#{!e.delDiscountPrice}">
	   							<h:outputText value="#{e.price.discountPrice} #{kUser.currency.sign}" 
	   								title="#{messages.discount_price_msg}"
	   								styleClass="bsk_item_price" />
  							</s:fragment>
 						</s:fragment>
						&#160;
						<h:outputText value="#{e.price.yourPrice} #{kUser.currency.sign}" 
							title="#{messages.your_price_msg}"
							rendered="#{kBasketManager.userDiscounted}" styleClass="bsk_item_price" />
	    			</rich:column>
	    			<rich:column styleClass="tac" width="10%">
	    				<f:facet name="header">
	    					<h:outputText value="#{messages.quantity_msg}" />
	    				</f:facet>
	    				<h:panelGroup>
		    				<h:inputText id="q_id" value="#{e.quantity}" size="2" required="true" styleClass="tar" >
		    					<f:validator validatorId="kPositiveValidator" />
		    				</h:inputText>&#160;
	 						<rich:message for="q_id" errorClass="errormsg">
	 							<f:facet name="errorMarker">
						    		<h:graphicImage url="/img/bad.png"/>
						    	</f:facet>
	  						</rich:message>
	    				</h:panelGroup>
	    			</rich:column>
	    			<rich:column styleClass="tar">
	    				<f:facet name="header">
	    					<h:outputText value="#{messages.sum_msg}" />
	    				</f:facet>
	    				<h:outputText value="#{e.sum} #{kUser.currency.sign}" styleClass="bsk_item_price"/>
	    			</rich:column>
	    			<rich:column>
	    				<f:facet name="header">
	    					<h:outputText value="#{messages.do_msg}" />
	    				</f:facet>
	    				<a:commandLink action="#{kBasketManager.remove(e)}" reRender="basket_id" >
	    					<h:graphicImage value="/img/cross.png" title="#{messages.delete_msg}" />
	    				</a:commandLink>
	    			</rich:column>
	    			<f:facet name="footer">
	    				<rich:columnGroup>
	    					<rich:column colspan="10" style="text-align:right;" styleClass="bsk_item_price">
    							<h:outputText value="#{messages.total_msg} = " />
    							<h:outputText value="#{kBasketManager.total} #{kUser.currency.sign}" />
    							<br />
    							<h:outputText value="#{kBasketManager.totalKadrons} K" />
    							<s:fragment rendered="#{kBasketManager.bonusAvb}">
	    							<h:outputText value="+#{kBasketManager.kadronDiscount.bonusKadrons} K" />
    							</s:fragment>
    						</rich:column>
    						<rich:column>
    							<a:commandButton 
					   				action="#{kBasketManager.order()}"
					   				onclick="if(!confirm('#{messages.confirm_order_msg}')) return false;"
					   				rendered="#{identity.loggedIn and kBasketManager.list.size gt 0}"
					   				reRender="basket_id,messages" value="#{messages.order_msg}" />
    						</rich:column>
	    				</rich:columnGroup>
	    			</f:facet>
	    		</rich:dataTable>
    		</h:form>
    	</h:panelGroup>
    </ui:define>
</ui:composition>
